package org.inspiration.dudu.message.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.inspiration.dudu.message.model.entity.MessageEntity;
import org.inspiration.dudu.message.model.vo.MessageVO;

import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<MessageEntity> {
    @Insert("insert into message(sender_id, receiver_id, content, message_type) values (#{senderId}, #{receiverId}, #{content}, #{messageType})")
    void save(MessageEntity messageEntity);

    @Select("select * from message where (sender_id = #{fromUserId} AND receiver_id = #{toUserId}) OR (sender_id = #{toUserId} AND receiver_id = #{fromUserId}) ORDER BY send_time DESC LIMIT #{offset}, #{pageSize}")
    List<MessageVO> getRecentMessages(Long fromUserId, Long toUserId, Integer offset, Integer pageSize);
}
